package dao

import (
	"context"

	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"

	userDao "dev-assistant-backend/internal/dao/user"
	"dev-assistant-backend/utility/configs"
)

func GetDB() gdb.DB {
	return g.DB()
}

func InitTables() {
	db := GetDB()

	dbType := configs.GetDBType(context.Background())

	if dbType == configs.DBTypeSqlite {

		var err error
		// 创建表
		_, err = db.Exec(context.Background(), userDao.CreateTableSqliteSQL)
		if err != nil {
			panic(err)
		}

		// 创建索引
		_, err = db.Exec(context.Background(), userDao.CreateSqliteIndexSQL)
		if err != nil {
			panic(err)
		}
	}
}
